package com.gec.teams.wechat.mapper;

import com.gec.teams.wechat.pojo.TbCheckin;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* @author Admin
* @description 针对表【tb_checkin(签到表)】的数据库操作Mapper
* @createDate 2024-06-12 22:40:29
* @Entity com.gec.teams.wechat.pojo.TbCheckin
*/
@Mapper
public interface TbCheckinMapper {

    int deleteByPrimaryKey(Long id);

    int insert(TbCheckin record);

    int insertSelective(TbCheckin record);

    TbCheckin selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(TbCheckin record);

    int updateByPrimaryKey(TbCheckin record);

    @Select("select id from tb_checkin where date=current_date and user_id=#{userId} " +
            "and create_time  BETWEEN #{start} and #{end} ")
    Integer haveCheckin(HashMap map);
//    查询上午的签到情况
    @Select("select address,create_time as checkin_time from tb_checkin where date=current_date and user_id=#{userId} and status<=2")
    HashMap searchTodayCheckin(int userId);
    @Select("select count(*) as count from tb_checkin where user_id=#{userId} group by date having count>=2")
    public List<Integer> searchCheckinDays(int userId);
    @Select("select CAST(date AS char) as date," +
            "case  " +
            "when status =1 then '正常' " +
            "when status =2 then '迟到' " +
            "when status =3 then '早退' " +
            "when status =4 then '正常' " +
            "else '无效' end status, " +
            "DATE_FORMAT(create_time,\'%H:%i\') AS checkinTime, date" +
            "        FROM tb_checkin" +
            "        WHERE user_id=#{userId}" +
            "          AND date BETWEEN #{startDate} AND #{endDate}")
    public ArrayList<HashMap> searchWeekCheckin(HashMap param);


    @Select("select date from tb_holidays where date between #{startDate} and #{endDate}")
    public ArrayList<String> searchHolidaysInRange(HashMap hashMap);

    @Select("select date from tb_workday where date between #{startDate} and #{endDate}")
    public ArrayList<String> searchWorkdayInRange(HashMap hashMap);

}
